<template>
	<!-- 没用，废弃 -->
	<view>
		<uni-forms ref="myForm" label-position="top">
			<uni-forms-item label="标题" >
				<uni-easyinput type="textarea" autoHeight v-model="formData.title" placeholder="标题" />
			</uni-forms-item>
			<uni-forms-item label="内容" >
				<uni-easyinput type="textarea" autoHeight v-model="formData.content" placeholder="内容" />
			</uni-forms-item>
		</uni-forms>
		<button type="primary" @click="submit()">保存</button>
	</view>
</template>

<script>
	import {getNoteByTid} from '@/api/note.js'
	
	export default{
		data(){
			return {
				// 基础表单数据
				formData: {
					title: '',
					content: ''
				},
				typeId:"",
				tid:"",
			}
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
			console.log(option.tid) //打印出上个页面传递的参数。
			this.tid = option.tid
			this.getNoteByTid()
		},
		methods:{
			submit() {
				if(this.formData.title === ""){
					this.formData.title = this.formData.content.slice(0,20)
				}
				saveNoteTitle(this.formData.title, this.formData.content, this.typeId)
			},
			getNoteByTid(){
				getNoteByTid(this.tid).then( res => {
					console.log("res:",res)
					this.formData.title = res.data.title
				})
			}
		}
	}
</script>

<style>
</style>